package com.xiaoa.gossip.cluster.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;


/**
 * @author luokaichuang
 * @time 2020/5/14
 */
//@Component
//@Aspect
public class LogAopAction {

    private static final Logger LOGGER = LoggerFactory.getLogger(LogAopAction.class);

    @Pointcut("execution(* com.xiaoa.gossip.cluster.action.*.*(..))")
    private void controllerMethodAspect() {
    }

    @Around("controllerMethodAspect()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        // 拦截的方法名称。当前正在执行的方法
        String methodName = pjp.getSignature().getName();
        Long startTime = System.currentTimeMillis();
        Object value = pjp.proceed();
        LOGGER.info("=== action ====== {}:{}", methodName, System.currentTimeMillis() - startTime);
        return value;

    }
}
